<?php
$nav=3;
include("conn/conn.php");
include("header.php");
if(!$_SESSION['username']){
    echo "<script>window.location.href='orderlogin.php';</script>";
	exit;
  }
$telphone = $_SESSION['telphone'];
$sql=mysql_query("select count(*) as total from tb_dingdan where isdelete=1  and xiadanren='".$_SESSION[username]."' and tel='".$telphone."' ",$conn);
$info=mysql_fetch_array($sql);
$total=$info[total];

?>

<!-- 内容 -->
		<div id="content">

<div class="login_content">
		    <div class="login_content_top"></div>
		    <div class="login_content_main"> 
		      <!--查询订单 开始-->
		      <div class="query_order"> 
			  <?php if($total==0){ ?>
					无订单信息
			   <?php }else{ ?>
		        <!--订单主要信息-->
			        <table class="query_order_table" border="1" width="100%">
			            <tbody>
						<tr>
			                <th width="10%">序号</th>
			                <th width="55%">订单状态</th>
			                <th width="20%">订单金额</th>
			                <th>操作</th>
			            </tr>
					</tbody>
					</table>
				<?php 
					$sql1=mysql_query("select * from tb_dingdan where isdelete=1 and xiadanren='".$_SESSION[username]."' and tel='".$telphone."' order by time desc limit 30",$conn);
				?>
				<?php
				$index=0;
				 while($info1=mysql_fetch_array($sql1)){
					$index++;
					$array=explode("@",$info1[spc]);
					$arrayquatity=explode("@",$info1[slc]);
				?>
		            <table class="wl_order_query query_order_table" border="1" width="100%">
				            <tbody><tr>
				                <td align="center" width="10%"><?php echo $index; ?></td>
				                <td width="55%"><div class="status_2"><span class="statu_img"><img src="kfc_files/status_1_b.png"></span><span><?php echo $info1['time']; ?>提交</span></div><div class="statu_icon"></div><div class="status_2"><span class="statu_img"><img src="kfc_files/status_2_a.png"></span></div><div class="statu_icon"></div><div class="status_2"><span class="statu_img"><img src="kfc_files/status_3_a.png"></span></div></td>
				                <td width="20%"><p><?php echo $info1['total']; ?>元</p>
				                <p>(货到现金付款)</p>
				                </td>
				                <td><div style="display: block;"><p class="print_icon"><a looyu_bound="1" href="print.php?orderid=<?php echo $info1['id'];?>">打印订单</a></p>
				                <p class="details_icon"><a looyu_bound="1" href="javascript:void(0);" onClick="toggle_order_detail(<?php echo $info1['id']; ?>)">查看详情</a></p></div></td>
				            </tr>
				        </tbody>
					</table>

					<div style="display: none;" class="query_order_details" id="order_detail_<?php echo $info1['id']; ?>">
						<div class="personal_info">
							<p><span class="personal_info_title">个人信息</span><span class="close_details"><a href="javascript:void(0);" onClick="toggle_order_detail(<?php echo $info1['id']; ?>)">关闭详情 </a></span></p>
							<p><span class="personal_info_span_1">顾客姓名：</span><span class="personal_info_span_2"><?php echo $info1['xiadanren']; ?></span></p>
							<p><span class="personal_info_span_1">联系电话：</span><span class="personal_info_span_2"><?php echo $info1['tel']; ?></span></p>
							<p><span class="personal_info_span_1">送餐地址：</span><span class="personal_info_span_2"><?php echo $info1['dizhi']; ?></span></p>
						</div>
						<div class="hr_1"></div>
						<div class="order_info">
							<p><span class="personal_info_title">订单详情</span></p>
							<table class="query_order_table_1" border="1" width="100%">
								<tbody><tr><th width="8%">序号</th><th width="20%">品名</th><th width="10%">单价</th><th width="8%">数量</th><th width="10%">小计</th></tr>
							<?php
							$total=0;
							$index2=0;
								for($i=0;$i<count($array)-1;$i++){
									$id=$array[$i];
									$num=$arrayquatity[$i];
									if($id!=""){
										$index2++;
										$sql=mysql_query("select * from tb_shangpin where id='".$id."'",$conn);
										$info=mysql_fetch_array($sql);
										$total1=number_format($num*$info[shichangjia],1);
										$total+=$total1;
							?>
									<tr>
										<td align="left"><?php echo $index2; ?></td>
										<td><?php echo $info[mingcheng]; ?></td>
										<td><span class="ft_color_red"><?php echo $info[shichangjia]; ?>元</span></td>
										<td><?php echo $num; ?></td>
										<td><span class="ft_color_red"><?php echo $total1; ?></span>元</td>
									</tr>

							<?php }}?>	
								</tbody>
							</table>
							<div class="total_price_div">
							<p><span class="total_price_span_query"><em class="ft_b">总金额：</em><?php echo $total; ?>元</span></p></div>
							<div class="hr_1"></div>
						</div>
					</div>
					
				<?php } ?>

			 <?php } ?>
				 </div>
		    </div>
		    <div class="login_content_btm"></div>
		  </div>
		</div>
		<!-- 版权信息 -->
		<!-- 弹出层 -->

<script type="text/javascript">

function toggle_order_detail(id){
	$('#order_detail_'+id).toggle();
}

</script>

<!--footer start-->
<?php include("footer.php");?>